﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BookShop.BLL;
using BookShop.Model;

namespace BookShop2
{
    public partial class CategoriesList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //DataList1.DataSource = CategoriesBLL.Getcategories();
            //DataList1.DataBind();
        }

        protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
            //使用对象的CommandArgument属性，获取前台传递过来的参数
            int categoryid = Convert.ToInt32(e.CommandArgument);
            //使用对象的CommandArgument属性，获取前台传递过来的参数(不同的按钮，commandname不同）
            string commandname=e.CommandName.ToString();
            if (commandname=="Del")
            {
                int i = CategoriesBLL.DelCategory(categoryid);
                if (i > 0)
                {
                    Response.Write("<script>alert('删除成功！')</script");
                    DataList1.DataBind();
                }else {
                    Response.Write("<script>alert('删除失败！')</script");
                }
            }

        }
    }
}